package com.yc.txx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yc.bean.Result;
import com.yc.biz.BizException;
import com.yc.txx.entity.TxxUser;
import com.yc.txx.entity.UserEx;
import com.yc.txx.mapper.TxxUserMapper;
import com.yc.txx.service.ITxxUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.validation.Errors;

import java.security.Timestamp;
import java.time.LocalDateTime;

/**
 * <p>
 * 天下行租车-用户表-4 服务实现类
 * </p>
 *
 * @author k
 * @since 2025-02-04
 */
@Service
public class TxxUserServiceImpl extends ServiceImpl<TxxUserMapper, TxxUser> implements ITxxUserService {

    @Override
    public void reg(UserEx user, Errors errors) throws BizException {
        if(!user.getRepwd().equals(user.getPassword())){
            errors.rejectValue("password","0000",
                    "确认密码与密码不一致");
        }
        // 同名验证
        LambdaQueryWrapper<TxxUser> lqw = new LambdaQueryWrapper<>();
        lqw.eq(TxxUser::getEname, user.getEname());
        if (count(lqw)>0) {
            errors.rejectValue("upass1","0001",
                    "该用户名已经注册!");
        }
        if (errors.hasErrors()) {
            throw new BizException("字段验证错误!", errors.getAllErrors());
        }
        user.setCreatetime(LocalDateTime.now());
        this.save(user);
    }
}
